package com.eating8.base.context;

import org.springframework.beans.factory.BeanFactoryUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.core.task.TaskExecutor;

@SuppressWarnings("unchecked")
public class SpringLocator {

	private static ApplicationContext applicationContext;

	public static <T> T getBean(String name) {
		return (T) applicationContext.getBean(name);
	}

	public static <T> T getBean(Class<T> clazz) {
		return (T) BeanFactoryUtils.beanOfType(applicationContext, clazz);
	}

	public static void setApplicationContext(ApplicationContext applicationContext) {
		SpringLocator.applicationContext = applicationContext;
	}

	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}

	public static TaskExecutor getDefaultTaskExecutor() {
		return getBean("taskExecutor");
	}

}
